# -*- coding: utf-8 -*-
from tc58.agent_list import agent_random
from tc58.ip_pro_test import ip_randm_get
from scrapy.http import HtmlResponse
STATUS_LIST = [502, 404, 403]
class user_random_agen(object):
    #切换ua
    #STATUS_LIST = [502, 404, 403]
    def process_request(self,request,spider):
        # print(requests.headers['user-agent'])
        request.headers['user-agent']=agent_random
        print(request.headers['User-Agent'])

class User_ranmo_ip(object):

    def process_request(self,request,spider):
        ips=ip_randm_get()
        ips.Take_one_ip()

        # print(ips.ip)
        proxy=ips.ip
        #print(proxy)
        request.meta['proxy']=proxy
        print(request.meta['proxy'])
        return None

    # def process_response(self,request,response,spider):
    #     return  response
    #     # if response.status in STATUS_LIST:
    #     #     ips = ip_randm_get()
    #     #     ips.Take_one_ip()
    #     #
    #     #     # print(ips.ip)
    #     #     proxy = ips.ip
    #     #     # print(proxy)
    #     #     request.meta['proxy'] = proxy
    #     #     new_response=HtmlResponse(url=request.url,body=response,encoding='utf-8',request=request)
    #     #     return  new_response
    #     # else:
    #     #     return response
    #
    #
    #
    # def process_exception(self,request,exception,spider):
    #     pass
